package com.rjwh.dingdong.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import com.aishua.lib.utils.AsStrUtils;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.localbean.HomeWorkFansFollowListItemData;
import com.rjwh.dingdong.client.util.ViewHolder;

/**
 * @author 王小珂
 * @ClassName HomeWorkFansFollowListAdapter
 * @Description
 * @date 2017-1-6
 * @history 2017-1-6 author: description:
 */
public class HomeWorkFansFollowListAdapter extends AdapterBase<HomeWorkFansFollowListItemData> {

    private Context context;
    private OnFollowBtnClickListener listener;

    public HomeWorkFansFollowListAdapter(Context context, OnFollowBtnClickListener listener) {
        this.context = context;
        this.listener = listener;
    }

    @Override
    protected View getExView(final int position, View convertView, ViewGroup parent) throws Exception {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.home_work_fans_follow_list_item, null);
        }

        TextView homeWorkFansFollowListItemNameTv = ViewHolder.get(convertView, R.id.home_work_fans_follow_list_item_name_tv);
        final ImageButton homeWorkFansFollowListItemBtn = ViewHolder.get(convertView, R.id.home_work_fans_follow_list_item_btn);

        final HomeWorkFansFollowListItemData homeWorkFansFollowListItemData = getList().get(position);
        if (homeWorkFansFollowListItemData == null) {
            return convertView;
        }

        final String isfollow = homeWorkFansFollowListItemData.getIsfollow();
        String name = homeWorkFansFollowListItemData.getName();

        if (!AsStrUtils.isEmpty(name)) {
            homeWorkFansFollowListItemNameTv.setText(name);
        }
        if (!AsStrUtils.isEmpty(isfollow)) {
            switch (isfollow) {
                case "1":
                    //未关注
                    homeWorkFansFollowListItemBtn.setImageResource(R.drawable.icon_fans_isfollowed);
                    break;
                case "2":
                    //互相关注
                    homeWorkFansFollowListItemBtn.setImageResource(R.drawable.icon_fans_follow_each_other);
                    break;
                case "3":
                    //未关注
                    homeWorkFansFollowListItemBtn.setImageResource(R.drawable.icon_fans_unfollow);
                    break;

                default:
                    break;
            }

        }

        homeWorkFansFollowListItemBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.onFollowBtnClick(homeWorkFansFollowListItemData, position);
                }
            }
        });

        return convertView;
    }

    public interface OnFollowBtnClickListener {
        void onFollowBtnClick(HomeWorkFansFollowListItemData data, int position);
    }
}
